package com.snail.billing.util;

import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

public class SnailPayUtil {
	
	/**
	 * 手机设备管理器。
	 */
	private static TelephonyManager telephonyManager;

	/**
	 * 获取手机运营商信息。
	 */
	public static String getProviderName(Context context) {
		if (telephonyManager == null) {
			telephonyManager = (TelephonyManager) context.getSystemService(
					Context.TELEPHONY_SERVICE);
		}
		String providerId = telephonyManager.getSubscriberId();
		if (!TextUtils.isEmpty(providerId)) {
			if (providerId.startsWith("46000") || providerId.startsWith("46002")) {
				// return "中国移动";
				return "2";
			} else if (providerId.startsWith("46001")) {
				// return "中国联通";
				return "4";
			} else if (providerId.startsWith("46003")) {
				// return "中国电信";
				return "3";
			}
		}
		return "";
	}
	
	/**
	 * 获取手机的IMEI值，为手机的唯一标示符。
	 * 
	 * @return 手机的IMEI值。
	 */
	public static String getIMEICode(Context context) {
		if (telephonyManager == null) {
			telephonyManager = (TelephonyManager) context.getSystemService(
					Context.TELEPHONY_SERVICE);
		}
		return telephonyManager.getDeviceId();
	}
	
	public static String getMacAddress(Context context) {
		WifiManager wifi = (WifiManager) context.getSystemService(
				Context.WIFI_SERVICE);
		WifiInfo info = wifi.getConnectionInfo();
		if (info != null) {
			String macAddress = info.getMacAddress();
			Log.d("TAG", "mac address is " + macAddress);
			return macAddress;
		}
		return "";
	}
	
	public static String getAppVersion(Context context) {
		try {
			return context.getPackageManager()
					.getPackageInfo(context.getPackageName(), Context.MODE_PRIVATE).versionName;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}

}
